package com.zxx.mvpPractice.ui.activitys;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.v4.app.Fragment;

import com.google.common.base.Preconditions;
import com.zxx.mvpPractice.R;
import com.zxx.mvpPractice.base.BaseActivity;
import com.zxx.mvpPractice.presenter.LoginFragmentPresenter;
import com.zxx.mvpPractice.presenter.LoginPresenter;
import com.zxx.mvpPractice.presenter.contract.LoginContract;
import com.zxx.mvpPractice.ui.adapter.ContentPagerAdapter;
import com.zxx.mvpPractice.ui.fragment.LoginPwdFragment;
import com.zxx.mvpPractice.ui.fragment.LoginRegisterFragment;
import com.zxx.mvpPractice.ui.fragment.MissPwdFragment;
import com.zxx.mvpPractice.utils.EventUtil;
import com.zxx.mvpPractice.view.weight.UnScrollViewPager;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/12/23 0023.
 */

public class LoginActivity extends BaseActivity<LoginContract.Presenter> implements LoginContract.View {

    @BindView(R.id.vp_content)
    UnScrollViewPager vpContent;
    ContentPagerAdapter mPagerAdapter;
    private ProgressDialog dialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        unbinder = ButterKnife.bind(this);
        mPresenter = new LoginPresenter(this);
        initViews();
    }

    private void initViews() {
        List<Fragment> fragments = initFragments();
        vpContent.setScrollable(false);
        mPagerAdapter = new ContentPagerAdapter(getSupportFragmentManager(), fragments);
        vpContent.setAdapter(mPagerAdapter);
        vpContent.setOffscreenPageLimit(fragments.size());
    }

    @Override
    public void setPresenter(LoginContract.Presenter presenter) {
        mPresenter = Preconditions.checkNotNull(presenter);
    }

    @Override
    public void showError(String msg) {
        EventUtil.showToast(this, msg);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    private List<Fragment> initFragments() {
        List<Fragment> fragments = new ArrayList<>();
        Fragment loginPwdFragment = new LoginPwdFragment();
        Fragment loginRegisterFragment = new LoginRegisterFragment();
        Fragment missPwdFragment = new MissPwdFragment();
        fragments.add(loginRegisterFragment);
        fragments.add(loginPwdFragment);
        fragments.add(missPwdFragment);
        return fragments;
    }

    public void jumpToMissPwd() {
        vpContent.setCurrentItem(2, true);
    }

    public void jumpToRegisterLogin() {
        vpContent.setCurrentItem(0, true);
    }

    public void jumpToLogin() {
        vpContent.setCurrentItem(1, true);
    }
}
